#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>

using namespace std;

vector<int> productExceptSelf(vector<int>& nums) {
    int n = nums.size();
    vector<int> res(n);
    res[0] = 1;
    for (int i = 1; i < n; i++)
        res[i] = res[i - 1] * nums[i - 1];
    int r = 1;
    for (int i = nums.size() - 1; i >= 0; i--)
    {
        res[i] *= r;
        r *= nums[i];
    }
    return res;
}

int firstMissingPositive(vector<int>& nums) {
    int n = nums.size();
    for (auto& it : nums)
        if (it <= 0)
            it = n + 1;

    for (auto it : nums)
    {
        int num = abs(it);
        if (num <= n)
            nums[num - 1] = -abs(nums[num - 1]);
    }

    for (int i = 0; i < n; i++)
        if (nums[i] > 0)
            return i + 1;
    return n + 1;
}